import 'package:flutter/material.dart';
import 'package:opene/app_theme.dart';
import 'package:opene/app_utils.dart';
import 'package:opene/ui/lpnphoto/lpnphotomodel.dart';
import 'package:opene/ui/tally/tallymodel.dart';

class LPNPhotoDetailDialog extends StatefulWidget {
  Tally tally;
  List<LPNPhotoDetail> tallyDetails = new List();

  LPNPhotoDetailDialog({this.tally, this.tallyDetails});

  @override
  _LPNPhotoDetailDialogDialogState createState() => _LPNPhotoDetailDialogDialogState(tally: tally, tallyDetails: this.tallyDetails);
}

class _LPNPhotoDetailDialogDialogState extends State<LPNPhotoDetailDialog> {
  Tally tally;
  List<LPNPhotoDetail> tallyDetails = new List();

  _LPNPhotoDetailDialogDialogState({this.tally, this.tallyDetails});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Detail(${tally.containerNo})", style: MyAppTheme.title),
            SizedBox(height: 16.0),
            Row(
              children: [
                Expanded(
                    flex: 2,
                    child: Text(
                      'LPN',
                      style: MyAppTheme.caption,
                    )),
                Expanded(flex: 1, child: Text('SKU', style: MyAppTheme.caption)),
                Expanded(flex: 1, child: Text('QTY', style: MyAppTheme.caption)),
              ],
            ),
            Flexible(
              fit: FlexFit.loose,
              child: setListView(),
            ),
            // Expanded(
            //   child: setListView(),
            // ),
            // setListView(),
            // SizedBox(height: 5.0),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Close',
                        style: MyAppTheme.title,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }

  ListView setListView() {
    return ListView.builder(
      shrinkWrap: true,
      // physics: NeverScrollableScrollPhysics(),
      itemCount: tallyDetails == null ? 0 : tallyDetails.length,
      itemBuilder: (context, index) {
        LPNPhotoDetail tallyDetail = tallyDetails[index];
        return Column(
          children: [
            Row(
              children: [
                Expanded(
                    flex: 2,
                    child: Text(
                      tallyDetail.lpn,
                      style: MyAppTheme.text_11_333333,
                    )),
                Expanded(flex: 1, child: Text(Utils.getStringisEmpty(tallyDetail.sku), style: MyAppTheme.text_11_333333)),
                Expanded(flex: 1, child: Text('${tallyDetail.quantity}', style: MyAppTheme.text_11_333333)),
              ],
            ),
            Divider(),
          ],
        );
      },
    );
  }
}
